# 社区service层
from flask import jsonify
import dao.CommunityDao as CommunityDao
import vo.CommunityVo as CommunityVo


# 按照要求返回社区页面的帖子
def service_community_default(pagination, amount, rule):
    result_dao = CommunityDao.dao_community_default(pagination, amount, rule)
    result = CommunityVo.vo_community_default(result_dao)
    return jsonify(result)


# 文章详情页
def service_community_detail(articleId, uuid):
    result_dao = CommunityDao.dao_community_detail(articleId, uuid)
    result = CommunityVo.vo_community_detail(result_dao)
    return jsonify(result)


# 发评论
def service_community_sendCommit(articleId, content, uuid):
    # 数据库中加入新评论
    result_dao = CommunityDao.dao_community_sendCommit(articleId, content, uuid)
    result = CommunityVo.vo_community_sendCommit(result_dao)
    return jsonify(result)


# 文章点赞/取消点赞
def service_community_articleLike(articleId, like, uuid):
    # true点赞，false取消点赞
    result_dao = CommunityDao.dao_community_articleLike(articleId, like, uuid)
    result = CommunityVo.vo_community_articleLike(result_dao)
    return jsonify(result)


# 评论点赞/取消点赞
def service_community_commitLike(commitId, like, uuid):
    # true点赞，false取消点赞
    result_dao = CommunityDao.dao_community_commitLike(commitId, like, uuid)
    result = CommunityVo.vo_community_commitLike(result_dao)
    return jsonify(result)


# 评论点赞/取消点赞
def service_community_replyLike(replyId, like, uuid):
    # true点赞，false取消点赞
    result_dao = CommunityDao.dao_community_replyLike(replyId, like, uuid)
    result = CommunityVo.vo_community_replyLike(result_dao)
    return jsonify(result)


# 评论回复
def service_community_reply(commitId, uuid, content):
    # 后端生成一个replyId
    result_dao = CommunityDao.dao_community_reply(commitId, uuid, content)
    result = CommunityVo.vo_community_reply(result_dao)
    return jsonify(result)
